var i = 0;
var timer;
var out_trade_no;

var payType = "";
$(document).ready(function(){
	
	document.onkeydown = function (e)
	{
		var ev = window.event || e;
		var code = ev.keyCode || ev.which;
		if (code == 116)
		{
			ev.keyCode ? ev.keyCode = 0 : ev.which = 0;
			cancelBubble = true;
			return false;
		}
    } //禁止f5刷新
	document.oncontextmenu=function(){return false};//禁止右键刷新
	
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/getOrdersByStudentId",
		async:false,
		data:{
			StudentId:student_id
		},
		success:function(result)
		{
			payType = result.extend.code;
		}
	});
	
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/getStudentById",
		async:true,
		data:{
			StudentId:student_id
		},
		success:function(result)
		{
			var promiseType = result.extend.student.promiseType;
			if(promiseType==1 && payType==1)
				window.location.href = "affirmMess.html";
			
			var cardId = result.extend.student.cardId;
			var graduationType = result.extend.student.graduationType;
			var examineeType = result.extend.student.examineeType;
			
			document.getElementById("cardId").innerHTML = cardId;
			switch (graduationType)
			{
				case 1:
					document.getElementById("graduationType").innerHTML = '高中';
					break;
				case 2:
					document.getElementById("graduationType").innerHTML = '中等师范';
					break;
				case 3:
					document.getElementById("graduationType").innerHTML = '中等专业学校';
					break;
				case 4:
					document.getElementById("graduationType").innerHTML = '职业高中学校';
					break;
				case 5:
					document.getElementById("graduationType").innerHTML = '技工学校';
					break;
			}
			switch (examineeType)
			{
				case 1:
					document.getElementById("examineeType").innerHTML = '城市应届';
					break;
				case 2:
					document.getElementById("examineeType").innerHTML = '农村应届';
					break;
				case 3:
					document.getElementById("examineeType").innerHTML = '城市往届';
					break;
				case 4:
					document.getElementById("examineeType").innerHTML = '农村往届';
					break;
			}
		}
	});
	
	out_trade_no = window.sessionStorage.getItem("out_trade_no");
	var body1 = window.sessionStorage.getItem("body1");
	var code_url = window.sessionStorage.getItem("code_url");
	
	document.getElementById("out_trade_no").innerHTML = out_trade_no;
	document.getElementById("body1").innerHTML = body1;
	$("#erweima").qrcode({ 
		render:"table",
		width:116,
		height:116,
		correctLevel:0,
		text:code_url
	});
	timer = setInterval(ajax_request, 3000);
	
/*	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/weixinpay",
		async:true,
		data:{
			id:student_id
		},
		success:function(result)
		{
			out_trade_no = result.extend.returnMap.out_trade_no;
			var code_url = result.extend.returnMap.code_url;
			var body1 = result.extend.returnMap.body;
			
			document.getElementById("out_trade_no").innerHTML = out_trade_no;
			document.getElementById("body1").innerHTML = body1;
			$("#erweima").qrcode({ 
				render:"table",
				width:116,
				height:116,
				correctLevel:0,
				text:code_url
			});
			timer = setInterval(ajax_request, 3000);
			//ajax_request();
		}
	});*/
});

function ajax_request(){
	i++;
	//如果已经请求20此没有请求成功，则强制结束，给出提示信息，因为每3s调用一次，供调用20次，大概就是一分钟的时间
	if(i == 100){
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/close",
		async:true,
		data:{
			orderid:out_trade_no
		}
	});
	alert("支付超时，订单已关闭");
	window.location.href = "affirmMess.html";
	}
	$.ajax({
	type: "GET",
	cache:false,
	url:rootPath+"/getTypeById",
	async:true,
	data:{
		orderId:out_trade_no
	},
	success: function (result){ 
	if(2 == result.extend.Type){
	return false;
	}else if(1 == result.extend.Type)
		{
	    window.location.href = "jumping.html";
	     }
	},
	error: function(){
	}
	});
}